package com.smartstate.dataManagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smartstate.dataManagement.dto.PageDTO;
import com.smartstate.dataManagement.entity.CarbonEmissions;
import com.smartstate.dataManagement.mapper.EmissionsMapper;
import com.smartstate.dataManagement.service.EmissionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EmissionsImpl extends ServiceImpl<EmissionsMapper, CarbonEmissions> implements EmissionsService {

    @Autowired
    EmissionsMapper emissionsMapper;

    @Override
    public Page<CarbonEmissions> queryAllPageByDTO(PageDTO pageDTO) {
        Page page = new Page(pageDTO.getPage(), pageDTO.getSize());
        QueryWrapper<CarbonEmissions> queryWrapper = new QueryWrapper<>();
        return emissionsMapper.selectPage(page, queryWrapper);
    }

    @Override
    public boolean removeAssetById(int id) {
        int b = emissionsMapper.deleteById(id);
        if (b == 1 ){
            return true;
        }
        return false;
    }

    @Override
    public int getCarbon(CarbonEmissions carbonEmissions) {
        Integer data = emissionsMapper.getData(carbonEmissions.getDateContribution());
        if (data != 0){
            return 0;
        }
        return 1;
    }
}
